<template>
	<div class="game-container report-container">
		<div class="view-container dealer-container">
			<div class="params">
				<el-form
					ref="form"
					:inline="true"
					:model="queryData"
					label-width="auto"
				>
					<el-form-item
						:label="`${$t('common.belong_merchant')}:`"
						class="tagheight"
					>
						<merchant-select
							v-model="queryData.merchantId"
							:merchantInfo.sync="merchantObj"
						></merchant-select>
					</el-form-item>
					<el-form-item :label="`${$t('funds.transfer_time')}:`">
						<el-date-picker
							v-model="searchTime"
							size="medium"
							:picker-options="pickerOptions"
							format="yyyy-MM-dd HH:mm:ss"
							type="datetimerange"
							range-separator="-"
							:start-placeholder="$t('common.start_date')"
							:end-placeholder="$t('common.end_date')"
							align="right"
							:clearable="false"
							:default-time="defaultTime"
						></el-date-picker>
					</el-form-item>
					<el-form-item :label="`${$t('funds.order_no')}:`">
						<el-input
							v-model="queryData.orderId"
							clearable
							size="medium"
							:placeholder="$t('common.please_enter')"
							:disabled="loading"
							@keyup.enter.native="enterSearch"
						></el-input>
					</el-form-item>
					<el-form-item :label="`${$t('funds.user_name')}:`">
						<el-input
							v-model="queryData.memberName"
							clearable
							size="medium"
							:placeholder="$t('common.please_enter')"
							:disabled="loading"
							@keyup.enter.native="enterSearch"
						></el-input>
					</el-form-item>
					<el-form-item
						:label="
							`${$t(
								'funds.proxy_member_funds_record.from_nallet'
							)}:`
						"
						class="tagheight"
					>
						<el-select
							v-model="queryData.fromWallet"
							clearable
							:placeholder="$t('common.select_all')"
							:popper-append-to-body="false"
						>
							<el-option
								v-for="item in bwVenueList"
								:key="item.gameCode"
								:label="item[getKey('venueName')]"
								:value="item.gameCode"
							></el-option>
						</el-select>
					</el-form-item>
					<el-form-item
						:label="
							`${$t(
								'funds.proxy_member_funds_record.to_wallet'
							)}:`
						"
						class="tagheight"
					>
						<el-select
							v-model="queryData.toWallet"
							clearable
							:placeholder="$t('common.select_all')"
							:popper-append-to-body="false"
						>
							<el-option
								v-for="item in bwVenueList"
								:key="item.gameCode"
								:label="item[getKey('venueName')]"
								:value="item.gameCode"
							></el-option>
						</el-select>
					</el-form-item>
					<el-form-item
						:label="
							`${$t(
								'funds.proxy_member_funds_record.order_status'
							)}:`
						"
						class="tagheight"
					>
						<el-select
							v-model="queryData.transferStatus"
							clearable
							:placeholder="$t('common.select_all')"
							:popper-append-to-body="false"
						>
							<el-option
								v-for="item in memberTransferStatus"
								:key="item.code"
								:label="item.description"
								:value="item.code"
							></el-option>
						</el-select>
					</el-form-item>
					<el-form-item style="margin-left: 8px">
						<el-button
							type="primary"
							icon="el-icon-search"
							:disabled="loading"
							size="medium"
							@click="search"
						>
							{{ $t('common.search') }}
						</el-button>
						<el-button
							icon="el-icon-refresh-left"
							:disabled="loading"
							size="medium"
							@click="reset"
						>
							{{ $t('common.reset') }}
						</el-button>
						<el-button
							v-if="hasPermission('404041')"
							icon="el-icon-download"
							type="warning"
							:disabled="loading"
							size="medium"
							@click="handleExportExcel"
						>
							{{ $t('common.export') }}
						</el-button>
					</el-form-item>
				</el-form>
			</div>
			<div class="content">
				<el-table
					v-loading="loading"
					border
					size="mini"
					show-summary
					:data="tableData"
					style="width: 100%"
					class="small-size-table"
					:header-cell-style="getRowClass"
					element-loading-spinner="el-icon-loading"
					:summary-method="(val) => handleRow(val, summary)"
				>
					<el-table-column
						prop="orderId"
						align="center"
						min-width="260"
						:label="$t('funds.order_no')"
					>
						<template slot-scope="scope">
							<Copy :title="scope.row.orderId" :copy="copy">
								{{ scope.row.orderId }}
							</Copy>
						</template>
					</el-table-column>
					<el-table-column
						prop="memberName"
						align="center"
						:label="$t('funds.user_name')"
						min-width="130"
					>
						<template slot-scope="scope">
							<Copy
								v-if="scope.row.memberName"
								:title="scope.row.memberName"
								:copy="copy"
							>
								{{ scope.row.memberName }}
							</Copy>
							<span v-else>-</span>
						</template>
					</el-table-column>
					<el-table-column
						prop="merchantId"
						align="center"
						:label="$t('common.belong_merchant')"
						min-width="120"
					>
						<template slot-scope="scope">
							{{ merchantFilter(scope.row.merchantId) }}
						</template>
					</el-table-column>
					<el-table-column
						prop="windControlName"
						align="center"
						:label="$t('funds.wind_control_level')"
						min-width="150"
					>
						<template slot-scope="scope">
							{{ scope.row.windControlName || '-' }}
						</template>
					</el-table-column>
					<el-table-column
						prop="fromWallet"
						align="center"
						:label="
							$t('funds.proxy_member_funds_record.from_nallet')
						"
						min-width="120"
					>
						<template slot-scope="scope">
							{{ handleFromWallet(scope.row.fromWallet) }}
						</template>
					</el-table-column>
					<el-table-column
						prop="toWallet"
						align="center"
						:label="$t('funds.proxy_member_funds_record.to_wallet')"
						min-width="120"
					>
						<template slot-scope="scope">
							{{ handleFromWallet(scope.row.toWallet) }}
						</template>
					</el-table-column>
					<el-table-column
						prop="transferStatus"
						align="center"
						:label="
							$t('funds.proxy_member_funds_record.order_status')
						"
						min-width="100"
					>
						<template slot-scope="scope">
							{{
								typeFilter(
									scope.row.transferStatus,
									'memberTransferStatus'
								)
							}}
						</template>
					</el-table-column>
					<el-table-column
						prop="amount"
						align="center"
						:label="
							$t(
								'funds.proxy_member_funds_record.transfer_amount'
							)
						"
						min-width="200"
					>
						<template slot-scope="scope">
							{{ handleCurrency(scope.row.bwCurrencyEnum) }}
							{{
								handleNumber(
									scope.row.bwCurrencyEnum,
									scope.row.amount
								)
							}}
						</template>
					</el-table-column>
					<el-table-column
						prop="occurDt"
						align="center"
						:label="$t('funds.transfer_time')"
						min-width="200"
					></el-table-column>
					<el-table-column
						prop="result"
						align="center"
						:label="$t('common.remark')"
						min-width="200"
					>
						<template slot-scope="scope">
							{{ scope.row.result || '-' }}
						</template>
					</el-table-column>
				</el-table>
				<!-- 分页 -->
				<el-pagination
					:current-page.sync="pageNum"
					class="pageValue"
					background
					layout="total, sizes,prev, pager, next, jumper"
					:page-size="pageSize"
					:page-sizes="pageSizes"
					:total="total"
					@current-change="handleCurrentChange"
					@size-change="handleSizeChange"
				></el-pagination>
			</div>
		</div>
	</div>
</template>

<script>
import list from '@/mixins/list'
import dayjs from 'dayjs'
import { routerNames } from '@/utils/consts'
import summaryList from './components/summaryList'
const startTime = dayjs()
	.startOf('day')
	.valueOf()
const endTime = dayjs()
	.endOf('day')
	.valueOf()

export default {
	name: routerNames.memberTransferRecord,
	mixins: [list, summaryList],
	data() {
		return {
			queryData: {},
			searchTime: [startTime, endTime],
			tableData: [],
			summary: {},
			merchantObj: '',
			bwVenueList: []
		}
	},
	computed: {
		memberTransferStatus() {
			return this.globalDics.memberTransferStatus || []
		}
	},
	created() {
		this.getVenueName()
	},
	mounted() {},
	methods: {
		async getVenueName() {
			const { data } = await this.$api.getReportVenueNameList({})
			const arr = JSON.parse(JSON.stringify(data)) || []
			arr.unshift({
				gameCode: 'center',
				venueName: this.$t('dict.send_position.0.description'),
				venueEnName: this.$t('dict.send_position.0.description'),
				venueThName: this.$t('dict.send_position.0.description'),
				venueVnName: this.$t('dict.send_position.0.description')
			})
			this.bwVenueList = arr
		},
		handleFromWallet(val) {
			let text = ''
			this.bwVenueList.forEach((ele) => {
				if (ele.gameCode === val) {
					text = ele.venueName
				}
			})
			return text || '-'
		},
		loadData() {
			this.loading = true
			const timeArr = this.searchTime || []
			const params = {
				...this.queryData,
				occurDtStart: dayjs(timeArr[0]).format('YYYY-MM-DD HH:mm:ss'),
				occurDtEnd: dayjs(timeArr[1]).format('YYYY-MM-DD HH:mm:ss'),
				...this.getParams(params)
			}
			this.pageCurrency = this.merchantObj?.currency || ''
			this.$api
				.getMemberTransferRecordsList(params)
				.then((res) => {
					this.loading = false
					const { record, totalRecord, summary } = res.data || {}
					this.tableData = record || []
					this.total = totalRecord
					this.summary = summary || {}
				})
				.catch(() => {
					this.loading = false
				})
		},
		reset() {
			this.pageNum = 1
			this.queryData = {}
			this.merchantObj = ''
			this.searchTime = [startTime, endTime]
			this.loadData()
		},
		handleExportExcel() {
			const timeArr = this.searchTime || []
			const params = {
				...this.queryData,
				occurDtStart: dayjs(timeArr[0]).format('YYYY-MM-DD HH:mm:ss'),
				occurDtEnd: dayjs(timeArr[1]).format('YYYY-MM-DD HH:mm:ss'),
				...this.getParams(params)
			}
			this.exportExcel(params)
		}
	}
}
</script>

<style lang="scss" scoped>
::v-deep .el-table__fixed-footer-wrapper .cell,
::v-deep .el-table__footer-wrapper .cell {
	height: 100%;
	padding: 0 !important;
	margin: 0 !important;
	> div {
		height: 100%;
	}
}
::v-deep .footer_count_row {
	min-height: 50px;
	height: 50%;
	display: flex;
	font-weight: 700;
	padding: 5px 0;
	align-items: center;
	flex-direction: column;
	justify-content: center;
}
::v-deep .footer_count_row_border {
	border-top: 1px solid #ebeef5;
}
</style>
